//
//  HLDiscussCell.m
//  HLAerospace
//
//  Created by hulian-ios on 17/9/11.
//  Copyright © 2017年 hulian-LB. All rights reserved.
//

#import "HLDiscussCell.h"
#import <Masonry/Masonry.h>
#import "HLCourseDiscuss.h"

@interface HLDiscussCell()

/** titleL  */
@property (nonatomic ,strong) UILabel *titleL;
/** contentL  */
@property (nonatomic ,strong) UILabel *contentL;
/** authorL  */
@property (nonatomic ,strong) UILabel *authorL;
/** timeL  */
@property (nonatomic ,strong) UILabel *timeL;


@end

@implementation HLDiscussCell

- (UILabel *)titleL
{
    if (!_titleL ) {
        _titleL = [[UILabel alloc] init];
        _titleL.textColor = HLRGB(60, 60, 60);
        _titleL.font = [UIFont boldSystemFontOfSize:IS_IPHONE_5 ? 14:(kMainTitleFontSize + 2)];
    }
    return _titleL;
}

- (UILabel *)contentL
{
    if (!_contentL ) {
        _contentL = [[UILabel alloc] init];
        _contentL.numberOfLines = 0;
        _contentL.text = @"";
        _contentL.textColor = HLRGB(60, 60, 60);
        _contentL.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 14:(kMainTitleFontSize + 2)];
    }
    return _contentL;
}

- (UIView *)line
{
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = HLRGB(235, 235, 235);
    }
    return _line;
}

- (UILabel *)authorL
{
    if (!_authorL ) {
        _authorL = [[UILabel alloc] init];
        _authorL.text = @"";
        _authorL.textColor = HLRGB(120, 120, 120);
        _authorL.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: 14];
    }
    return _authorL;
}

- (UILabel *)timeL
{
    if (!_timeL ) {
        _timeL = [[UILabel alloc] init];
        _timeL.text = @"";
        _timeL.textColor = HLRGB(120, 120, 120);
        _timeL.textAlignment = NSTextAlignmentRight;
        _timeL.font = [UIFont systemFontOfSize:IS_IPHONE_5 ? 12: 14];
    }
    return _timeL;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.backgroundColor = HLRGB(245, 245, 245);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self setUI];
    }
    return self;
}

- (void)setUI
{
    [self.contentView addSubview:self.titleL];
    [self.contentView addSubview:self.contentL];
    [self.contentView addSubview:self.authorL];
    [self.contentView addSubview:self.timeL];
    [self.contentView addSubview:self.line];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self configsCons];
}

- (void)configsCons
{
    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.top.equalTo(self.contentView).offset(5);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(@(25));
    }];
    
    [self.authorL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.width.equalTo(@(self.width *0.5));
        make.height.equalTo(@(25));
    }];
    
    [self.timeL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).offset(-10);
        make.bottom.equalTo(self.contentView).offset(-5);
        make.width.equalTo(@(self.width *0.4));
        make.height.equalTo(@(25));
    }];

    [self.contentL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.top.equalTo(self.titleL.mas_bottom).offset(15);
        make.right.equalTo(self.contentView).offset(-10);
        make.bottom.equalTo(self.authorL.mas_top).offset(- 15);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(10);
        make.bottom.equalTo(self.contentView);
        make.right.equalTo(self.contentView).offset(-10);
        make.height.equalTo(@(1));
    }];
}

- (void)setCourseDiscuss:(HLCourseDiscuss *)courseDiscuss
{
    _courseDiscuss = courseDiscuss;
//    self.contentL.text = [courseDiscuss.title_content stringByRemovingPercentEncoding];
    self.contentL.text = courseDiscuss.title_content;
    self.titleL.text = [courseDiscuss.title stringByRemovingPercentEncoding];
    self.authorL.text = courseDiscuss.user;
    self.timeL.text = courseDiscuss.time;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end
